﻿using System;
using System.Windows.Forms;
using WcfTest.GuiClient.Presenters;
using WcfTest.GuiClient.Views;

namespace WcfTest.GuiClient.Forms
{
	public partial class MainForm : Form, IMainView
	{
		#region Fields

		private readonly MainPresenter presenter;

		#endregion Fields

		#region Constructors

		public MainForm()
		{
			InitializeComponent();
			presenter = new MainPresenter(this);
		}

		#endregion Constructors

		#region IMainView implementation

		public string TalkingServiceUrl
		{
			get { return TalkingServiceUrlTextBox.Text; }
			set { TalkingServiceUrlTextBox.Text = value; }
		}

		public void EnterNormalMode()
		{
			Enabled = true;
		}

		public void EnterWaitMode()
		{
			Enabled = false;
		}

		public void Log(string message)
		{
			LogRichTextBox.AppendText(string.Concat(message, Environment.NewLine));
		}

		public void LogError(string message)
		{
			LogRichTextBox.AppendText(string.Format("ERROR: {0}{1}", message, Environment.NewLine));
		}

		#endregion IMainView implementation

		#region Event handlers

		private void MainForm_Load(object sender, EventArgs e)
		{
			presenter.OnLoad();
		}

		private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
		{
			presenter.OnClosing();
		}

		private void SayButton_Click(object sender, EventArgs e)
		{
			presenter.OnSayButtonClick();
		}

		private void TalkingServiceUrlTextBox_TextChanged(object sender, EventArgs e)
		{
			presenter.OnTalkingServiceUrlChanged();
		}

		#endregion Event handlers
	}
}
